Skip to content

Conversation

@yronglin
Copy link
Contributor

This PR mark P2788R0(DR) as implemented and added more test.

P2788R0 implemented by 62a16d5.

@yronglin yronglin requested review from ChuanqiXu9 and cor3ntin June 14, 2025 08:04
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jun 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 14, 2025

@llvm/pr-subscribers-clang

Author: None (yronglin)

Changes

This PR mark P2788R0(DR) as implemented and added more test.

P2788R0 implemented by 62a16d5.


Full diff: https://github.com/llvm/llvm-project/pull/144214.diff

2 Files Affected:

  • (modified) clang/test/CXX/basic/basic.link/p3.cpp (+80-25)
  • (modified) clang/www/cxx_status.html (+1-1)
diff --git a/clang/test/CXX/basic/basic.link/p3.cpp b/clang/test/CXX/basic/basic.link/p3.cpp
index 01202264d2591..22c298394c2a6 100644
--- a/clang/test/CXX/basic/basic.link/p3.cpp
+++ b/clang/test/CXX/basic/basic.link/p3.cpp
@@ -1,35 +1,23 @@
-// RUN: %clang_cc1 -std=c++2a -verify %s
-// RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=1
-// RUN: %clang_cc1 -std=c++2a -verify %s -DIMPORT_ERROR=2
+// RUN: rm -rf %t
+// RUN: split-file %s %t
 
+// RUN: %clang_cc1 -std=c++20 -verify %t/M.cppm
+// RUN: %clang_cc1 -std=c++20 -verify %t/ImportError1.cppm
+// RUN: %clang_cc1 -std=c++20 -verify %t/ImportError2.cppm
+// RUN: %clang_cc1 -std=c++20 -Wno-reserved-module-identifier -emit-module-interface %t/std.cppm -o %t/std.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/A.cppm -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/A-B.cppm -o %t/A-B.pcm
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify -fmodule-file=std=%t/std.pcm -fmodule-file=A=%t/A.pcm -fmodule-file=A:B=%t/A-B.pcm %t/A_impl.cppm
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify -fmodule-file=A=%t/A.pcm %t/User.cppm 
+
+//--- M.cppm
 module;
 
-#if IMPORT_ERROR != 2
 struct import { struct inner {}; };
-#endif
 struct module { struct inner {}; };
-
 constexpr int n = 123;
 
 export module m; // #1
-
-// Import errors are fatal, so we test them in isolation.
-#if IMPORT_ERROR == 1
-import x = {}; // expected-error {{expected ';' after module name}}
-               // expected-error@-1 {{module 'x' not found}}
-
-#elif IMPORT_ERROR == 2
-struct X;
-template<int> struct import;
-template<> struct import<n> {
-  static X y;
-};
-
-// This is not valid because the 'import <n>' is a pp-import, even though it
-// grammatically can't possibly be an import declaration.
-struct X {} import<n>::y; // expected-error {{'n' file not found}}
-
-#else
 module y = {}; // expected-error {{multiple module declarations}} expected-error 2{{}}
 // expected-note@#1 {{previous module declaration}}
 
@@ -51,4 +39,71 @@ template<typename T> module module_var_template;
 
 // This is a variable named 'import' that shadows the type 'import' above.
 struct X {} import;
-#endif
+
+//--- ImportError1.cppm
+module;
+
+struct import { struct inner {}; };
+struct module { struct inner {}; };
+
+constexpr int n = 123;
+
+export module m; // #1
+
+import x = {}; // expected-error {{expected ';' after module name}}
+               // expected-error@-1 {{module 'x' not found}}
+
+//--- ImportError2.cppm
+module;
+
+struct module { struct inner {}; };
+
+constexpr int n = 123;
+
+export module m; // #1
+
+struct X;
+template<int> struct import;
+template<> struct import<n> {
+  static X y;
+};
+
+// This is not valid because the 'import <n>' is a pp-import, even though it
+// grammatically can't possibly be an import declaration.
+struct X {} import<n>::y; // expected-error {{'n' file not found}}
+
+//--- A.cppm
+export module A;
+const double delta=0.01;
+export {
+  template<class F>
+  double derivative(F &&f,double x) {
+    return (f(x+delta)-f(x))/delta;
+  }
+}
+
+//--- std.cppm
+export module std;
+export using size_t = decltype(sizeof(void *));
+
+export namespace std {
+  template <typename T, size_t N>
+  struct array {};
+}
+
+//--- A-B.cppm
+module A:B;
+const int dimensions=3;
+
+//--- A_impl.cppm
+// expected-no-diagnostics
+module A;
+import std;
+import :B;
+
+using vector = std::array<double, dimensions>;  // error: lookup failed until P2788R0(Linkage for modular constants).
+
+//--- User.cppm
+// expected-no-diagnostics
+import A;
+double d=derivative([](double x) {return x*x;},2);  // error: names delta until P2788R0(Linkage for modular constants).
diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index dff57689e84b9..cd39ea830b57a 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -905,7 +905,7 @@ <h2 id="cxx20">C++20 implementation status</h2>
       </tr>
       <tr> <!-- from Issaquah 2023 -->
         <td><a href="https://wg21.link/P2788R0">P2788R0</a> (<a href="#dr">DR</a>)</td>
-        <td class="none" align="center">No</td>
+        <td class="none" align="center">Clang 17</td>
       </tr>
     <tr>
       <td>Coroutines</td>

Copy link
Member

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test changes LG.

@yronglin
Copy link
Contributor Author

Test changes LG.

Thanks for the review!

@yronglin
Copy link
Contributor Author

CC @Bigcheese @jansvoboda11 Could you help review this change?

@jansvoboda11 jansvoboda11 removed their request for review June 24, 2025 16:09
@cor3ntin
Copy link
Contributor

cor3ntin commented Jul 2, 2025

Adding @hubert-reinterpretcast

I think some / most of the tests are unrelated to the paper, but there seem to be sufficient tests in
62a16d5

@yronglin
Copy link
Contributor Author

yronglin commented Jul 9, 2025

Duplicated with #147138, I think we can close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants